package cn.iocoder.yudao.module.blog.convert.spacelike;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.controller.app.space.commentvo.AppBlogSpaceCommentRespVO;
import cn.iocoder.yudao.module.blog.controller.app.space.likevo.AppBlogSpaceLikeRespVO;
import cn.iocoder.yudao.module.blog.convert.base.BlogConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.spacecomment.BlogSpaceCommentDO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.blog.controller.admin.spacelike.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.spacelike.BlogSpaceLikeDO;

/**
 * 动态点赞 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogSpaceLikeConvert {

    BlogSpaceLikeConvert INSTANCE = Mappers.getMapper(BlogSpaceLikeConvert.class);

    BlogSpaceLikeDO convert(BlogSpaceLikeCreateReqVO bean);

    BlogSpaceLikeDO convert(BlogSpaceLikeUpdateReqVO bean);

    BlogSpaceLikeRespVO convert(BlogSpaceLikeDO bean);

    List<BlogSpaceLikeRespVO> convertList(List<BlogSpaceLikeDO> list);

    PageResult<BlogSpaceLikeRespVO> convertPage(PageResult<BlogSpaceLikeDO> page);

    List<BlogSpaceLikeExcelVO> convertList02(List<BlogSpaceLikeDO> list);
    default AppBlogSpaceLikeRespVO convertApp(BlogSpaceLikeDO bean, MemberUserRespDTO memberUserRespDTO){
        if ( bean == null ) {
            return null;
        }

        AppBlogSpaceLikeRespVO appBlogSpaceLikeRespVO = new AppBlogSpaceLikeRespVO();

        appBlogSpaceLikeRespVO.setMember(BlogConvert.INSTANCE.covnertMember(memberUserRespDTO));
        appBlogSpaceLikeRespVO.setId(bean.getId());
        appBlogSpaceLikeRespVO.setSpaceId(bean.getSpaceId());
        appBlogSpaceLikeRespVO.setMemberId(bean.getMemberId());

        return appBlogSpaceLikeRespVO;
    }

    default List<AppBlogSpaceLikeRespVO> convertAppList(List<BlogSpaceLikeDO> blogSpaceLikeDOList, Map<Long, MemberUserRespDTO> memberMap){
        List<AppBlogSpaceLikeRespVO> list = new ArrayList<>();
        blogSpaceLikeDOList.forEach(blogSpaceLikeDO -> {
            list.add(convertApp(blogSpaceLikeDO, memberMap.get(blogSpaceLikeDO.getMemberId())));
        });

        return list;
    }
    default PageResult<AppBlogSpaceLikeRespVO> convertAppPage(PageResult<BlogSpaceLikeDO> page, Map<Long, MemberUserRespDTO> memberMap ){
        if ( page == null ) {
            return null;
        }

        PageResult<AppBlogSpaceLikeRespVO> pageResult = new PageResult<AppBlogSpaceLikeRespVO>();
        List<AppBlogSpaceLikeRespVO> list = convertAppList(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }

}
